import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-uaa/clients/list',
  save = '/api-uaa/clients/saveOrUpdate',
  edit = '/api-uaa/clients/saveOrUpdate',
  detailClient = '/api-uaa/clients/{0}',
  deleteClient = '/api-uaa/clients/delete',
  deleteBatch = '/api-uaa/clients/deleteBatch',
  allClientList = '/api-uaa/clients/all',
  importExcel = '/api-uaa/clients/import',
  exportXls = '/api-uaa/clients/export',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除应用
 */
export const deleteClient = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteClient, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除应用
 * @param params
 */
export const batchDeleteClient = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新应用
 * @param params
 */
export const saveOrUpdateClient = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
/**
 * 获取全部应用
 */
export const allClientList = (params) => defHttp.get({ url: Api.allClientList, params });
/**
 * 获取应用详情
 */
export const getClientById = (params) => {
  const url = stringFormat(Api.detailClient, params.id);
  return defHttp.get({ url: url });
};
